IF OBJECT_ID('dbo.GetDeliverableSubContractors') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.GetDeliverableSubContractors
    IF OBJECT_ID('dbo.GetDeliverableSubContractors') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.GetDeliverableSubContractors >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.GetDeliverableSubContractors >>>'
END
go
-- =======================================================================
-- Procedure Name: dbo.GetDeliverableSubContractors
--
-- Author:      Kevin Cashman, Parallax Consulting LLC
--
-- Create date: 10/11/2008
--
-- Description: Returns list of SubContractors for Deliverables
--        Since for both "In" and "Out", have to search two different
--        tables. 
--
-- Parameters:  None
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.GetDeliverableSubContractors()
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 10/11/08    KC        Created
-- 12/11/08    KC        Changed to parse Subs from Deliverable Report
--                       Names.
--
-- =======================================================================
CREATE PROCEDURE dbo.GetDeliverableSubContractors
     (@Name                        VARCHAR(50)=NULL)
AS
BEGIN
     /*  Returned Fields for Dropdown
     --------------------------------
     Name           VARCHAR             
     */

     -- Initial Settings
     SET NOCOUNT ON
     
     -- Declare Local Variables
     DECLARE   @Error            INT,
               @RowCount         INT
               
     -- Result Query    
     SELECT DISTINCT dbo.fnParseSubcontractorName(DEL.ReportName) AS SubContractor
     FROM      dbo.vwInfoEdSubContractDeliverables DEL
     WHERE     @Name IS NULL OR RTRIM(dbo.fnParseSubcontractorName(DEL.ReportName)) LIKE '%' + @Name + '%' 
     ORDER BY dbo.fnParseSubcontractorName(DEL.ReportName)
     
     SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
     IF @Error!=0
          RETURN -1

     -- Return Success
     RETURN 0
     
END
go

IF OBJECT_ID('dbo.GetDeliverableSubContractors') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.GetDeliverableSubContractors >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.GetDeliverableSubContractors >>>'
go

GRANT EXECUTE ON dbo.GetDeliverableSubContractors TO InsightReport,Insight
go
